{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import codecs\n",
    "\n",
    "folder_path = './'\n",
    "\n",
    "narrator = \"旁白\"\n",
    "\n",
    "# 遍历文件夹中的所有文件\n",
    "for filename in os.listdir(folder_path):\n",
    "    if filename.endswith('.txt'):\n",
    "        file_path = os.path.join(folder_path, filename)\n",
    "\n",
    "        with codecs.open(file_path, 'r', 'utf-8') as file:\n",
    "            lines = file.readlines()\n",
    "            \n",
    "        new_lines = []\n",
    "        for line in lines:\n",
    "            line = line.replace('：', ': ')\n",
    "            if ':' in line and narrator not in line:\n",
    "                index = line.index(':') + 1\n",
    "                content_after_colon = line[index:].strip()\n",
    "                if not content_after_colon.startswith('「'):  # check if content after colon starts with 「\n",
    "                    line = line[:index] + '「' + content_after_colon + '」' + '\\n'\n",
    "                    \n",
    "            new_lines.append(line)\n",
    "\n",
    "        with codecs.open(file_path, 'w', 'utf-8') as file:\n",
    "            file.writelines(new_lines)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "pytorch",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.16"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
